package com.test26_比较器;

import java.util.Arrays;

public class Demo01_Test {

    public static void main(String[] args) {
        Book[] books = new Book[] {
                new Book("Java从入门到项目实战", 99.8),
                new Book("Python从入门到项目实战", 89.7),
                new Book("Go语言从入门到项目实战", 96.3)
        };
        // 会出现ClassCastException，不能将Book类的对象实例转为Comparable
        // Arrays.sort(books); // 数组排序处理
        Arrays.stream(books).forEach(System.out::println);
    }
}

class Book {
    private String title;
    private double price;

    public Book(String title, double price) {
        this.title = title;
        this.price = price;
    }

    @Override
    public String toString() {
        return "【Book】图书名称：" + this.title + "、图书价格：" + this.price;
    }
}
